$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/devicecharge/list',
        datatype: "json",
        colModel: [			
			// { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
			{ label: '充电宝编码', name: 'chargeSn', index: 'CHARGE_SN', width: 80 }, 			
			{ label: '租借次数', name: 'chargeCount', index: 'CHARGE_COUNT', width: 80 }, 			
			// { label: '充电宝编码', name: 'chargeSum', index: 'CHARGE_SUM', width: 80 },
			// { label: '所属系统', name: 'sysSystem', index: 'SYS_SYSTEM', width: 80 },
			// { label: '排序', name: 'sort', index: 'SORT', width: 80 },
			// { label: '状态', name: 'status', index: 'STATUS', width: 80 },
			// { label: '备注', name: 'remarks', index: 'REMARKS', width: 80 },
			{ label: '注册时间', name: 'createdTime', index: 'CREATED_TIME', width: 80 },
			// { label: '创建人员', name: 'createdUserId', index: 'CREATED_USER_ID', width: 80 },
			// { label: '修改时间', name: 'modifyTime', index: 'MODIFY_TIME', width: 80 },
			// { label: '修改人员', name: 'modifyUserId', index: 'MODIFY_USER_ID', width: 80 },
			// { label: '版本号', name: 'version', index: 'VERSION', width: 80 }
            { label: '操作', name: 'sy', width: 100,align:'center',formatter: function(cellvalue, options, rowdata) {
                    return "<a style='cursor:pointer;' onclick='vm.queryLog("+ rowdata.id +")'>" +
                        "日志</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                }}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        // prmNames : {
        //     page:"page",
        //     rows:"limit",
        //     order: "order"
        // },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
	    q: {
            chargeSn: null
        },
		showList: true,
		title: null,
		deviceCharge: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		// add: function(){
		// 	vm.showList = false;
		// 	vm.title = "新增";
		// 	vm.deviceCharge = {};
		// },
		queryLog: function (id) {
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfoLog(id)
		},
        getInfoLog: function(id){
            $("#jqGridAdd").jqGrid({
                type: "POST",
                async:false,
                url: baseURL + 'sys/devicecabinetlog/infoLogList/'+id,
                datatype: "json",
                colModel: [
                    // { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
                    { label: '机柜编码', name: 'cabinetId', index: 'CABINET_ID', width: 80 },
                    // { label: '二维码编号', name: 'qrCode', index: 'QR_CODE', width: 80 },
                    // { label: '开始时间', name: 'startTime', index: 'START_TIME', width: 80 },
                    // { label: '结束时间', name: 'endTime', index: 'END_TIME', width: 80 },
                    { label: '创建人员', name: 'createdUserId', index: 'CREATED_USER_ID', width: 80 },
                    { label: '所属系统', name: 'sysSystem', index: 'SYS_SYSTEM', width: 80 },
                    // { label: '排序', name: 'sort', index: 'SORT', width: 80 },
                    // { label: '状态', name: 'status', index: 'STATUS', width: 80 },
                    { label: '备注', name: 'remarks', index: 'REMARKS', width: 80 }
                    // { label: '创建时间', name: 'createdTime', index: 'CREATED_TIME', width: 80 },
                    // { label: '修改时间', name: 'modifyTime', index: 'MODIFY_TIME', width: 80 },
                    // { label: '修改人员', name: 'modifyUserId', index: 'MODIFY_USER_ID', width: 80 },
                    // { label: '版本号', name: 'version', index: 'VERSION', width: 80 }
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPager1",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            $('#myModal').modal();
        },
		// saveOrUpdate: function (event) {
		//     $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
        //         var url = vm.deviceCharge.id == null ? "sys/devicecharge/save" : "sys/devicecharge/update";
        //         $.ajax({
        //             type: "POST",
        //             url: baseURL + url,
        //             contentType: "application/json",
        //             data: JSON.stringify(vm.deviceCharge),
        //             success: function(r){
        //                 if(r.code === 0){
        //                      layer.msg("操作成功", {icon: 1});
        //                      vm.reload();
        //                      $('#btnSaveOrUpdate').button('reset');
        //                      $('#btnSaveOrUpdate').dequeue();
        //                 }else{
        //                     layer.alert(r.msg);
        //                     $('#btnSaveOrUpdate').button('reset');
        //                     $('#btnSaveOrUpdate').dequeue();
        //                 }
        //             }
        //         });
		// 	});
		// },
		// del: function (event) {
		// 	var ids = getSelectedRows();
		// 	if(ids == null){
		// 		return ;
		// 	}
		// 	var lock = false;
        //     layer.confirm('确定要删除选中的记录？', {
        //         btn: ['确定','取消'] //按钮
        //     }, function(){
        //        if(!lock) {
        //             lock = true;
		//             $.ajax({
        //                 type: "POST",
        //                 url: baseURL + "sys/devicecharge/delete",
        //                 contentType: "application/json",
        //                 data: JSON.stringify(ids),
        //                 success: function(r){
        //                     if(r.code == 0){
        //                         layer.msg("操作成功", {icon: 1});
        //                         $("#jqGrid").trigger("reloadGrid");
        //                     }else{
        //                         layer.alert(r.msg);
        //                     }
        //                 }
		// 		    });
		// 	    }
        //      }, function(){
        //      });
		// },
		// getInfo: function(id){
		// 	$.get(baseURL + "sys/devicecharge/info/"+id, function(r){
        //         vm.deviceCharge = r.deviceCharge;
        //     });
		// },
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData: {'chargeSn': vm.q.chargeSn
            },
                page:page
            }).trigger("reloadGrid");
		}
	}
});